package com.ims.form.FinancialAssistance.scholarshipinfo;

import com.ims.entity.ScholarShipEntity;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class scholarInfoReponse {
    private long recordQuantity;
    private List<ScholarShipEntity> scholarShipEntityList;

    public scholarInfoReponse(long recordQuantity, List<ScholarShipEntity> scholarShipEntityList) {
        this.recordQuantity = recordQuantity;
        this.scholarShipEntityList = scholarShipEntityList;
    }

    public long getRecordQuantity() {
        return recordQuantity;
    }

    public List<Object> getScholarShipEntityList() {
        ArrayList<Object> list = new ArrayList<>();
        for (ScholarShipEntity i : this.scholarShipEntityList) {
            Map<String, Object> map = new HashMap<>();
            Class clazz = i.getClass();
            Field[] fields = i.getClass().getDeclaredFields();
            try {
                for (Field field : fields) {
                    PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz);
                    Method getMothod = pd.getReadMethod();
                    Object o = getMothod.invoke(i);
                    if (!field.getName().equals("student")) {
                        map.put(field.getName(), o);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            map.put("number", i.getStudent().getStuId());
            map.put("name", i.getStudent().getStuName());
            map.put("major", i.getStudent().getMajor());
            map.put("_class", i.getStudent().getStuClass());
            list.add(map);
        }
        return list;
    }
}
